Introduction
The AxisMarker class can be used to highlight parts of a chart area along an axis. The axis marker can have a single value, a range, or even a CalendarPattern. An axis marker can also be attached to an element in cases where the marker is wanted on a category axis.
Axis markers can also be drawn on top of the chart elements when in 2D mode. This behavior can be specified by setting the AxisMarker.BringToFront property to true.
Single Value AxisMarker
An axis marker can take a number, DateTime, or string value to define it's position. This sample code snippet uses a number and string to insert markers.
[C#]
AxisMarker am1 = new AxisMarker("Marker at 45",new Line(Color.Orange),45);
AxisMarker am2 = new AxisMarker("Text marker at 'Element 0'",new Line(Color.Green),"Element 0");
Chart.XAxis.Markers.Add(am1, am2);
[Visual Basic]
Dim am1 As New AxisMarker("Marker at 45",new Line(Color.Orange),45)
Dim am2 As New AxisMarker("Text marker at 'Element 0'",new Line(Color.Green),"Element 0")
Chart.XAxis.Markers.Add(am1, am2)
Range AxisMarker
Axis markers can also highlight a range on the chart. Even a string range.
[C#]
AxisMarker am3 = new AxisMarker("20-30",new Background(Color.FromArgb(100,Color.LightBlue)),20,30);
AxisMarker am4 = new AxisMarker("'Element 1'-'Element 2'",new Background(Color.FromArgb(100,Color.LightBlue)),"Element 1","Element 2");
am4.Label.LineAlignment = StringAlignment.Near;
Chart.XAxis.Markers.Add(am3, am4);
[Visual Basic]
Dim am3 As New AxisMarker("20-30",New Background(Color.FromArgb(100,Color.LightBlue)),20,30)
Dim am4 As New AxisMarker("'Element 1'-'Element 2'",New Background(Color.FromArgb(100,Color.LightBlue)),"Element 1","Element 2")
am4.Label.LineAlignment = StringAlignment.Near
Chart.XAxis.Markers.Add(am3, am4)
Attached to an element
To attach an axis marker to an element simply instantiate one for the elements in question.
[C#]
myElement.AxisMarker = new AxisMarker("Attached to element 3",new Line(Color.Blue),0);
[Visual Basic]
myElement.AxisMarker = New AxisMarker("Attached to element 3",new Line(Color.Blue),0)
AxisMarkerAdvanced.aspx |
Calendar Pattern AxisMarker
A calendar pattern can be used to specify sections of time the axis marker is drawn on.
This example highlights the weekdays on a time x axis:
[C#]
CalendarPattern cp = new CalendarPattern(TimeInterval.Day,TimeInterval.Week,"0111110");
cp.AdjustmentUnit = TimeInterval.Day;
AxisMarker am = new AxisMarker("",new Background(Color.FromArgb(100,Color.Orange)),0,0);
am.CalendarPattern = cp;
Chart.XAxis.Markers.Add(am);
[Visual Basic]
Dim cp As New CalendarPattern(TimeInterval.Day,TimeInterval.Week,"0111110")
cp.AdjustmentUnit = TimeInterval.Day
Dim am As New AxisMarker("",New Background(Color.FromArgb(100,Color.Orange)),0,0)
am.CalendarPattern = cp
Chart.XAxis.Markers.Add(am)
See Also: Calendar Pattern Tutorial
Sample: calendarPattern.aspx |